package com.lanchetech.admin.controller;

import com.lanchetech.admin.aop.OperatorLog;
import com.lanchetech.admin.service.LotteryService;
import com.lanchetech.bean.request.LotteryOrderReq;
import com.lanchetech.bean.request.LotterySpuListReq;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.LotteryOrderResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.LotteryRecordVO;
import com.lanchetech.entity.Lottery;
import com.lanchetech.entity.Spu;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(value = "抽奖管理接口", tags = "抽奖管理接口")
@RequestMapping("/api/lottery")
@RestController
public class LotteryController {

    @Autowired
    LotteryService lotteryService;

    @OperatorLog("添加或编辑抽奖活动")
    @ApiOperation("添加或编辑抽奖活动")
    @PreAuthorize("hasAuthority('marketing.lottery.lottery-index.edit.auth')")
    @PostMapping("/editLottery")
    public BaseResp editLottery(@RequestBody Lottery req) {
        return lotteryService.editLottery(req);
    }

    @ApiOperation(value = "获取抽奖活动分页", notes = "筛选条件 status, type, name")
    @PreAuthorize("hasAuthority('marketing.lottery.lottery-index')")
    @PostMapping("/getLotteryPage")
    public ResultData<BasePageResp<Lottery>> getLotteryPage(@RequestBody PageReq req) {
        return lotteryService.getLotteryPage(req);
    }

    @OperatorLog("删除抽奖活动")
    @ApiOperation("删除抽奖活动")
    @PreAuthorize("hasAuthority('marketing.lottery.lottery-index.delete.auth')")
    @GetMapping("/deleteLottery")
    public BaseResp deleteLottery(@RequestParam("id") Long id) {
        return lotteryService.deleteLottery(id);
    }

    @ApiOperation("获取抽奖活动详情")
    @PreAuthorize("hasAuthority('marketing.lottery.lottery-index.edit.auth')")
    @GetMapping("/getLotteryDetail")
    public ResultData<Lottery> getLotteryDetail(@RequestParam("id") Long id) {
        return lotteryService.getLotteryDetail(id);
    }

    @ApiOperation(value = "获取抽奖记录分页", notes = "筛选条件 userId, relateId->lotteryId, status, scene->addressStatus, type, name")
    @PreAuthorize("hasAuthority('marketing.lottery.lottery-list')")
    @PostMapping("/getLotteryRecordPage")
    public ResultData<BasePageResp<LotteryRecordVO>> getLotteryRecordPage(@RequestBody PageReq req) {
        return lotteryService.getLotteryRecordPage(req);
    }

    @ApiOperation(value = "获取spu列表", notes = "获取spu列表")
    //@PreAuthorize("hasAuthority('marketing.lottery.lottery-list')")
    @GetMapping("/lotterySpuList")
    public ResultData<Spu> lotterySpuList(LotterySpuListReq lotterySpuListReq){
        return lotteryService.lotterySpuList(lotterySpuListReq);
    }

    @ApiOperation(value = "抽奖订单", notes = "抽奖订单")
    //@PreAuthorize("hasAuthority('marketing.lottery.lottery-list')")
    @GetMapping("/lotteryOrder")
    public ResultData<LotteryOrderResp> lotteryOrder(LotteryOrderReq lotteryOrderReq){
        return lotteryService.lotteryOrder(lotteryOrderReq);
    }


    @ApiOperation(value = "抽奖订单详情", notes = "抽奖订单详情")
    @GetMapping("/getLotteryOrderDetail")
    public ResultData<LotteryOrderResp> getLotteryOrderDetail(Long id){
        return lotteryService.getLotteryOrderDetail(id);
    }


}
